package com.springday2;

import com.springday2.dao.BookDao;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class AppForCoreContainer {
    public static void main(String[] args) {

//        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContextForDay2.xml");

//        这种方式要写完整路径
//        ApplicationContext ctx = new FileSystemXmlApplicationContext("E:\\javaProject\\springTest0625\\src\\main\\resources\\applicationContextForDay2.xml");

//        获取bean的方法一：
//        BookDao bookDao = (BookDao) ctx.getBean("bookDao");
//        获取bean的方法二：
//        BookDao bookDao = ctx.getBean("bookDao", BookDao.class);
//        获取bean的方法三：
//        BookDao bookDao = ctx.getBean(BookDao.class);
//        bookDao.save();

//        BeanFactory
        Resource resources = new ClassPathResource("applicationContextForDay2.xml");
        BeanFactory bf = new XmlBeanFactory(resources);

        BookDao bookDao = bf.getBean(BookDao.class);
        bookDao.save();
    }
}
